﻿using System;

namespace Terraria.World.Generation
{
	// Token: 0x0200008E RID: 142
	public abstract class GenCondition : GenBase
	{
		// Token: 0x06000A22 RID: 2594 RVA: 0x003E58A8 File Offset: 0x003E3AA8
		public bool IsValid(int x, int y)
		{
			switch (this._areaType)
			{
			case GenCondition.AreaType.And:
				for (int i = x; i < x + this._width; i++)
				{
					for (int j = y; j < y + this._height; j++)
					{
						if (!this.CheckValidity(i, j))
						{
							return this.InvertResults;
						}
					}
				}
				return !this.InvertResults;
			case GenCondition.AreaType.Or:
				for (int k = x; k < x + this._width; k++)
				{
					for (int l = y; l < y + this._height; l++)
					{
						if (this.CheckValidity(k, l))
						{
							return !this.InvertResults;
						}
					}
				}
				return this.InvertResults;
			case GenCondition.AreaType.None:
				return this.CheckValidity(x, y) ^ this.InvertResults;
			default:
				return true;
			}
		}

		// Token: 0x06000A23 RID: 2595 RVA: 0x0000AEE6 File Offset: 0x000090E6
		public GenCondition Not()
		{
			this.InvertResults = !this.InvertResults;
			return this;
		}

		// Token: 0x06000A24 RID: 2596 RVA: 0x0000AEF8 File Offset: 0x000090F8
		public GenCondition AreaOr(int width, int height)
		{
			this._areaType = GenCondition.AreaType.Or;
			this._width = width;
			this._height = height;
			return this;
		}

		// Token: 0x06000A25 RID: 2597 RVA: 0x0000AF10 File Offset: 0x00009110
		public GenCondition AreaAnd(int width, int height)
		{
			this._areaType = GenCondition.AreaType.And;
			this._width = width;
			this._height = height;
			return this;
		}

		// Token: 0x06000A26 RID: 2598
		protected abstract bool CheckValidity(int x, int y);

		// Token: 0x04000EA7 RID: 3751
		private bool InvertResults;

		// Token: 0x04000EA8 RID: 3752
		private int _width;

		// Token: 0x04000EA9 RID: 3753
		private int _height;

		// Token: 0x04000EAA RID: 3754
		private GenCondition.AreaType _areaType = GenCondition.AreaType.None;

		// Token: 0x0200008F RID: 143
		private enum AreaType
		{
			// Token: 0x04000EAC RID: 3756
			And,
			// Token: 0x04000EAD RID: 3757
			Or,
			// Token: 0x04000EAE RID: 3758
			None
		}
	}
}
